package com.example.commonmistak.designpatterns.template.service;

import com.example.commonmistak.designpatterns.template.db.Db;
import com.example.commonmistak.designpatterns.template.entity.Item;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * vip 用户购物车
 * @author xiongwei
 * @date 2022/1/14 10:57
 */
@Service("vipUserCart")
public class VipUserCart extends NormalUserCart {
    @Override
    protected void processCouponPrice(long userId, Item item) {
        item.setCouponPrice(BigDecimal.ZERO);
        if (item.getQuantity() > 2) {
            item.setCouponPrice(item.getPrice()
                    .multiply(Db.getUserCouponPercent(userId))
                    .multiply(BigDecimal.valueOf(item.getQuantity() - 2)));
        }
    }
}
